<?php

use D1M\Payment\Http\Controllers\CombinedPaymentController;
use D1M\Payment\Http\Controllers\PaymentController;
use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/

Route::get('/', function () {
    return 'welcome';
});


//生成二维码
Route::post('/qrcode','PartitionController@qrcode');



//登录
Route::post('/login','LoginController@login');
Route::post('/send/sms','LoginController@smsCode');
//获取登录用户信息
Route::get('/user/info','LoginController@userInfo');
Route::post('/check_token','LoginController@checkToken');
Route::post('/refresh_token','LoginController@refreshToken');
Route::post('/logout','LoginController@logout')->middleware('auth.login');

Route::middleware(['auth.login'])->group(function () {
//Route::middleware([])->group(function () {
    // 在此路由组中的所有路由必须先通过 Authenticate 中间件检查用户登录。
    Route::get('/test/token',function (){
        echo 'token ok!';
    });

    //创建购物车
    Route::post('/food/cart_create','CartController@store');
    //编辑购物车
    Route::post('/food/cart_edit','CartController@edit');

    //台面概览
    Route::get('/partition/table','PartitionController@partitionTable');
    Route::get('/partition/table/detail','PartitionController@tableDetail');


//开台
    Route::post('/open/table','PartitionController@openTable');

//清台
    Route::post('/clear/table','PartitionController@clearTable');

//换桌
    Route::post('/change/table','PartitionController@changeTable');
//切换用户
    Route::post('/change/user','PartitionController@changeTableUser');

    //调整金额
    Route::post('/change/order/amount','FoodOrderController@adjustment');
    Route::post('/clear/order/adjustment','FoodOrderController@clearAdjustment');


    Route::post('/change/product/user','ProductController@changeUser');
    Route::post('/product/order/detail','ProductController@productOrderDetail');

    //提交账单页面
    Route::post('/submit/page','PartitionController@tableFoodOrderDetail');

    Route::post('/user/register','UserController@register');

    //短信验证
    Route::post('/sms/send','SmsController@send');



/****************************************转发的接口 END****************************************/
//用户
Route::post('/user/list','ForwardController@getUserList');
Route::post('/user/unsorted/list','ForwardController@userList');
Route::post('/user/detail','ForwardController@getUserByManageNo');
Route::post('/user/order/detail','ForwardController@getUserOrderDetail');
Route::post('/user/consumption/records','ForwardController@userConsumptionRecords');

//零售商品信息
Route::post('/product/info','ForwardController@getProductInfo');
Route::post('/product/queryBySkuIds','ForwardController@getProductInfoByRetailOnlineId');//询零售商品信息 根据SKU上架的id集合
Route::post('/product/create-retail','ForwardController@createRetail');//提交订单#零售商品
Route::post('/product/update','ForwardController@editRetail');//零售单修改
Route::post('/product/retail-pending-list','ForwardController@getPendingRetailList');//挂起单列表
Route::post('/product/retail-pending-page','ForwardController@getPendingRetailPage');//挂起单列表（带分页）
Route::post('/product/resetOrder','ForwardController@delRetail');//清空零售单商品
Route::post('/product/retail-order-detail','ForwardController@getRetailDetail');//提交订单页面，零售单详情
Route::post('/product/sku/list','ForwardController@productSkuList');//搜索零售sku列表
//下单
Route::post('/food/list','ForwardController@foodList');
Route::post('/food/detail','ForwardController@foodDetail');
Route::post('/create/food/order','ForwardController@foodOrder');
Route::post('/create/product/order','ForwardController@createProductOrder');
Route::post('/food/order/detail','ForwardController@foodOrderDetail');
Route::post('/food/order/refund','ForwardController@foodOrderRefund');
Route::post('/food/order/close','ForwardController@foodOrderClose');
Route::post('/food/order/statistics','ForwardController@foodOrderStatistics');
//餐饮单下单
Route::post('/food/order/create','ForwardController@foodOrderAdd');
Route::post('/food/stock/list','ForwardController@foodStockList');
Route::post('/add/order','ForwardController@addOrder');
Route::post('/add/sku','ForwardController@addSku');
Route::post('/del/sku','ForwardController@delSku');
Route::post('/order/detail','ForwardController@orderDetail');
Route::post('/get/order/no','ForwardController@getOrderNo');
Route::post('/get/order/info','ForwardController@getOrderInfo');
Route::post('/get/order/list','ForwardController@getOrderList');
Route::post('/order/list','ForwardController@orderList');
Route::post('/order/rollback','ForwardController@orderRollback');


//打印
Route::post('/print/order/list','ForwardController@printOrderList');
Route::post('/print/order/tag','ForwardController@printOrderTag');
Route::post('/print/order/receipt','ForwardController@printOrderReceipt');
Route::post('/print/part/tag','ForwardController@printPartTag');


//充值
Route::post('/member/card','ForwardController@memberCard');
Route::post('/order/card','ForwardController@orderCard');

//优惠券
Route::post('/user/voucher/list','ForwardController@userVoucherList');
Route::post('/user/voucher/calculate','ForwardController@userVoucherCalculate');


/****************************************转发的接口 END****************************************/
});

//java sign
Route::get('/get_sign','PartitionController@getSign');
Route::get('/get_token','PartitionController@getToken');
Route::post('/api/get_php_sign','PartitionController@getPhpSign');



//提供给java的API
Route::post('/api/refreshToken','PartitionController@refreshPhpToken');
Route::post('/api/getToken','PartitionController@getPhpToken');
Route::middleware(['auth.api'])->prefix('api')->group(function () {
    // 在此路由组中的所有路由必须先通过 Authenticate 中间件检查token及签名
    Route::post('/test',function (){
        echo 'token && sign  ok';
    });

    //后台接口
    //Route::apiResource('/partitions', 'PartitionController',
        //['only' => ['store']]);//get post put/id delete/id get/id
    Route::post('/partition/list','PartitionController@index');
    Route::post('/partitions','PartitionController@store');
    Route::post('/partition/delete','PartitionController@destroy');

    //区域排序
    Route::post('/partition/order','PartitionController@order');
    //启用、停用桌台
    Route::post('/partition/table/update','PartitionController@changeTableState');
    Route::post('/partition/table/delete','PartitionController@softDeleteTable');

    //收钱吧配置
    Route::post('/shouqianba/setting_edit','ShouqianbaSettingController@setting');
    Route::post('/shouqianba/setting_list','ShouqianbaSettingController@getList');

    //退款申请接口
    Route::post('/refund','RefundController@index');
    //退款结果查询接口
    Route::post('/refund_query','RefundController@query');

    //支付结果反查
    Route::post('/pay/get_payment_result','PaymentController@getResult');

    //订单或退单完成
    Route::post('/orderOrRefund/confirm','OrderController@confirm');

    // 给 ES 系统调用的支付相关接口
    Route::prefix('/pay')->group(function () {
        // 创建组合支付单，用于 POS机 创建组合支付单，通过武汉 ES 系统内部调用。
        Route::post('/combined_payments', [CombinedPaymentController::class, 'create']);

        // 获取支付单列表
        Route::get(
            '/combined_payments/{id}/payments',
            [PaymentController::class, 'getPayments']
        );
    });

    //storeTableRecord 用户用户列表的桌台展示
    Route::post('/user/table/records','PartitionController@storeTableRecord');

    //回滚调整金额
    //Route::post('/rollback/adjustment','PartitionController@rollbackAdjustment');

});

// 支付接口：POS机前端调用。
// 需要验证店员已登录，只要登录了就可以获取支付信息、发起支付，
// 不需要验证哪个支付单是由哪个店员创建的。
Route::group([
    'prefix' => '/pay',
    'middleware' => ['auth.login'],
], function () {
    // 获取组合支付单
    Route::get(
        '/combined_payments/{id}',
        [CombinedPaymentController::class, 'getById']
    );

    // 支付
    Route::post('/payments', [PaymentController::class, 'pay']);
});

//收钱吧退款结果通知
Route::post('/shouqianba/refund/{id}/notifications','ShouqianbaController@receiveNotification')->name('refund-notifications');